<?php

$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("title")->setDescription("description");

$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle("Statistik Absensi Mahasiswa");
$a = 3;
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(18);
$objPHPExcel->getActiveSheet()->mergeCells('A1:D1')->setCellValue('A1', 'Statistik Absensi Mahasiswa');
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(0)->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(1)->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(2)->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(3)->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(4)->setAutoSize(true);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $a, 'No');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $a, 'NRP');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $a, 'Nama Mahasiwa');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $a, 'Total Absen');
$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A'.$a.':D'.$a)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A'.$a.':D'.$a)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A'.$a.':D'.$a)->getFill()->getStartColor()->setARGB('bebebf');

$a++;
$no=1;
foreach($qabsensi as $row){
	$objPHPExcel->getActiveSheet()->getRowDimension($a)->setRowHeight(25);
	$objPHPExcel->getActiveSheet()->getStyle('A'.$a.':D'.$a)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
	$objPHPExcel->getActiveSheet()->getStyle('A'.$a.':D'.$a)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $a, $no);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $a, $row["NRP"]);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $a, $row["NAMA"]);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $a, $row["TOTAL_ABSENSI"]);
	$no++;
	$a++;
}
// Save it as an excel 2007 file
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment;filename='Cetak Statistik Absensi Mahasiswa.xlsx'");
header('Cache-Control: max-age=0');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
?>